package net.mcreator.toolsasfood.procedures;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.animal.Pig;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerLevel;

public class CarrotStickSummonPigZaiXiaoGuoChiXuShiMeiKeFaShengProcedure {
	public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
		if (entity == null)
			return;
		if (entity.getPersistentData().getDouble("carrotStick") % 100 == 0) {
			if (world instanceof ServerLevel _level) {
				Entity entityToSpawn = new Pig(EntityType.PIG, _level);
				entityToSpawn.moveTo(x, y, z, world.getRandom().nextFloat() * 360F, 0);
				if (entityToSpawn instanceof Mob _mobToSpawn)
					_mobToSpawn.finalizeSpawn(_level, world.getCurrentDifficultyAt(entityToSpawn.blockPosition()), MobSpawnType.MOB_SUMMONED, null,
							null);
				world.addFreshEntity(entityToSpawn);
			}
		}
		entity.getPersistentData().putDouble("carrotStick", (entity.getPersistentData().getDouble("carrotStick") + 1));
	}
}
